

*******************************************************************************
* Title: The Democrat Disaster: Hurricane Exposure, Risk Aversion and Insurance Demand
* Author: Raluca L Pahontu
*******************************************************************************


cd "~/Dropbox/Replication/JoP/"

global input "~/Dropbox/Replication/JoP/input"
global temp "~/Dropbox/Replication/JoP/temp/"
global output "~/Dropbox/Replication/JoP/figures/"

***************************
* Analysis  for Figure E2
* Analysis for Figure E3
* Analysis for Figure F1
* Analysis for Figure F2
* Analysis for Figure F3
* Analysis for Table E1
* Analysis for Table E2
* Analysis for Table C1
* Analysis for Table C4
* Analysis for Table E3 
* Analysis for Table B2
* Analysis for Table B3
* Analysis for Table B4
* Analysis for Table B5
* Analysis for Table B6
* Analysis for Table B7
* Analysis for Table B8
* Analysis for Table B9
* Analysis for Table B10
* Analysis for Table B11
* Analysis for Figure B5
* Analysis for Figure B1, uses data that is not publicly available
* Analysis for Figure B2, uses data that is not publicly available
* Analysis for Figure B3, uses data that is not publicly available
* Analysis for Figure B4, uses data that is not publicly available
* Analysis for Table D1, Table D2, Figure D1, Figure D2, Figure D3, Figure D4, uses data that is not publicly available
***************************


* Figure E2

preserve
import delim "$input/gtrends_house_regressiondata.csv", clear

reg zillow logd google yahoo bing i.stateid i.monthid i.year , cl(stateid)
regsave logd using "$temp/fige2data.dta", table(zillowcoef, order(regvars)) replace tstat pval ci
reg redfin logd google yahoo bing i.stateid i.monthid i.year , cl(stateid)
regsave logd using "$temp/fige2data.dta", table(redfincoef, order(regvars)) append tstat pval ci
reg remax logd google yahoo bing i.stateid i.monthid i.year , cl(stateid)
regsave logd using "$temp/fige2data.dta", table(remaxcoef, order(regvars)) append tstat pval ci
reg agent logd google yahoo bing i.stateid i.monthid i.year , cl(stateid)
regsave logd using "$temp/fige2data.dta", table(agentcoef, order(regvars)) append tstat pval ci
restore


* Figure E3
preserve
import delim "$input/zillow_county_regressiondata.csv", clear
reg sales logd i.stateid##i.monthid i.year , cl(stateid)
regsave logd using "$temp/fige3bdata", table(homevalue, order(regvars)) replace tstat pval ci
import delim "$input/zillow_countysales_regressiondata.csv", clear
reg sales logd i.stateid##i.monthid i.year , cl(stateid)
regsave logd using "$temp/fige3adata", table(housesales, order(regvars)) replace tstat pval ci
restore

* Figure F1

preserve 
use "$input/cces-religion", clear
qui reg religious evertr500 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr500 using "$temp/ccesrelig", table(evertr500, order(regvars)) replace   ci

qui  reg religious evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using "$temp/ccesrelig", table(evertr400, order(regvars)) append   ci

qui reg religious evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using "$temp/ccesrelig", table(evertr300, order(regvars)) append   ci

qui reg religious evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using "$temp/ccesrelig", table(evertr200, order(regvars)) append   ci

qui reg religious evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using "$temp/ccesrelig", table(evertr100, order(regvars)) append   ci

qui reg religious evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using "$temp/ccesrelig", table(evertr50, order(regvars)) append   ci

use "$temp/ccesrelig", clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf1data", replace
rm "$temp/ccesrelig.dta"
restore

* Figure F2

preserve 
use "$input/cces-authoritarian", clear

qui reg authoritarian1 evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using ccesauth1, table(evertr500, order(regvars)) replace   ci

qui reg   authoritarian1 evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using ccesauth1, table(evertr400, order(regvars)) append   ci

qui reg  authoritarian1 evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using ccesauth1, table(evertr300, order(regvars)) append   ci

qui reg  authoritarian1 evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using ccesauth1, table(evertr200, order(regvars)) append   ci

qui reg  authoritarian1 evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using ccesauth1, table(evertr100, order(regvars)) append   ci

qui reg  authoritarian1 evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using ccesauth1, table(evertr50, order(regvars)) append   ci



qui reg authoritarian2 evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using ccesauth2, table(evertr500, order(regvars)) replace   ci

qui reg   authoritarian2 evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using ccesauth2, table(evertr400, order(regvars)) append   ci

qui reg  authoritarian2 evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using ccesauth2, table(evertr300, order(regvars)) append   ci

qui reg  authoritarian2 evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using ccesauth2, table(evertr200, order(regvars)) append   ci

qui reg  authoritarian2 evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using ccesauth2, table(evertr100, order(regvars)) append   ci


qui reg  authoritarian2 evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using ccesauth2, table(evertr50, order(regvars)) append   ci




qui reg authoritarian3 evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using ccesauth3, table(evertr500, order(regvars)) replace   ci

qui reg   authoritarian3 evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using ccesauth3, table(evertr400, order(regvars)) append   ci

qui reg  authoritarian3 evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using ccesauth3, table(evertr300, order(regvars)) append   ci

qui reg  authoritarian3 evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using ccesauth3, table(evertr200, order(regvars)) append   ci

qui reg  authoritarian3 evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using ccesauth3, table(evertr100, order(regvars)) append   ci

qui reg  authoritarian3 evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using ccesauth3, table(evertr50, order(regvars)) append   ci




qui reg authoritarian4 evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using ccesauth4, table(evertr500, order(regvars)) replace   ci

qui reg   authoritarian4 evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using ccesauth4, table(evertr400, order(regvars)) append   ci

qui reg  authoritarian4 evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using ccesauth4, table(evertr300, order(regvars)) append   ci

qui reg  authoritarian4 evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using ccesauth4, table(evertr200, order(regvars)) append   ci

qui reg  authoritarian4 evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using ccesauth4, table(evertr100, order(regvars)) append   ci

qui reg  authoritarian4 evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using ccesauth4, table(evertr50, order(regvars)) append   ci



use ccesauth1, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf21dta", replace
rm "ccesauth1.dta"



use ccesauth2, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf22data", replace
rm "ccesauth2.dta"



use ccesauth3, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf23data", replace
rm "ccesauth3.dta"


use ccesauth4, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf24data", replace
rm "ccesauth4.dta"
restore

* Figure F3

preserve
use "$input/cces-authoritarian", clear

gen infrastructurespending = 0 if CC16_426_5 == 4 | CC16_426_5 == 5 
replace infrastructurespending = 0.5 if CC16_426_5 == 3 
replace infrastructurespending = 1 if CC16_426_5 == 1 | CC16_426_5 == 2 

 
reg infrastructurespending evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using ccesinfra, table(evertr500, order(regvars)) replace   ci

reg   infrastructurespending evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using ccesinfra, table(evertr400, order(regvars)) append   ci

reg  infrastructurespending evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using ccesinfra, table(evertr300, order(regvars)) append   ci

reg  infrastructurespending evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using ccesinfra, table(evertr200, order(regvars)) append   ci

reg  infrastructurespending evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using ccesinfra, table(evertr100, order(regvars)) append   ci

reg  infrastructurespending evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using ccesinfra, table(evertr50, order(regvars)) append   ci


reg  CC16_351F evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using cceshighact, table(evertr500, order(regvars)) replace   ci

reg    CC16_351F evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using cceshighact, table(evertr400, order(regvars)) append   ci

reg  CC16_351F evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using cceshighact, table(evertr300, order(regvars)) append   ci

reg   CC16_351F evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using cceshighact, table(evertr200, order(regvars)) append   ci

reg   CC16_351F evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using cceshighact, table(evertr100, order(regvars)) append   ci

reg   CC16_351F evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using cceshighact, table(evertr50, order(regvars)) append   ci



reg  CC16_427_c evertr500 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr500 using cceslocalroad, table(evertr500, order(regvars)) replace   ci

reg    CC16_427_c evertr400 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr400 using cceslocalroad, table(evertr400, order(regvars)) append   ci

reg  CC16_427_c evertr300 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr300 using cceslocalroad, table(evertr300, order(regvars)) append   ci

reg   CC16_427_c evertr200 i.income_quarters female age i.race i.educ employed out_of_labour   , r
regsave evertr200 using cceslocalroad, table(evertr200, order(regvars)) append   ci

reg   CC16_427_c evertr100 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr100 using cceslocalroad, table(evertr100, order(regvars)) append   ci

reg   CC16_427_c evertr50 i.income_quarters female age i.race i.educ employed out_of_labour  , r
regsave evertr50 using cceslocalroad, table(evertr50, order(regvars)) append   ci



use ccesinfra, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf31data", replace
rm "ccesinfra.dta"




use cceshighact, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf32data", replace
rm "cceshighact.dta"



use cceslocalroad, clear

drop if var == "r2" 
drop if var == "N" 

reshape long evertr, i(var) j(led)
drop if evertr == .


replace var =  "coef" if var == "evertr50_coef" 
replace var =  "coef" if var == "evertr100_coef" 
replace var =  "coef" if var == "evertr200_coef" 
replace var =  "coef" if var == "evertr300_coef" 
replace var =  "coef" if var == "evertr400_coef" 
replace var =  "coef" if var == "evertr500_coef" 


replace var =  "ci_upper" if var == "evertr50_ci_upper" 
replace var =  "ci_upper" if var == "evertr100_ci_upper" 
replace var =  "ci_upper" if var == "evertr200_ci_upper" 
replace var =  "ci_upper" if var == "evertr300_ci_upper" 
replace var =  "ci_upper" if var == "evertr400_ci_upper" 
replace var =  "ci_upper" if var == "evertr500_ci_upper" 



replace var =  "ci_lower" if var == "evertr50_ci_lower" 
replace var =  "ci_lower" if var == "evertr100_ci_lower" 
replace var =  "ci_lower" if var == "evertr200_ci_lower" 
replace var =  "ci_lower" if var == "evertr300_ci_lower" 
replace var =  "ci_lower" if var == "evertr400_ci_lower" 
replace var =  "ci_lower" if var == "evertr500_ci_lower" 


reshape wide evertr, i(var) j(led)
drop if var == "evertr100_stderr"
drop if var == "evertr200_stderr"
drop if var == "evertr300_stderr"
drop if var == "evertr400_stderr"
drop if var == "evertr500_stderr"
drop if var == "evertr50_stderr"
save "$temp/figf33data", replace
rm "cceslocalroad.dta"
restore



preserve 
use "$input/prec-hur", clear
xtset group

qui xtreg demosenshare_total treatment50 i.year i.stateid, fe cl(group)
regsave treatment50 using "$temp/fig3adata", table(dist50, order(regvars)) replace tstat pval ci

qui xtreg demosenshare_total treatment100 i.year i.stateid, fe cl(group)
regsave treatment100 using "$temp/fig3adata", table(dist100, order(regvars)) append tstat pval ci

qui xtreg demosenshare_total treatment200 i.year i.stateid, fe cl(group)
regsave treatment200 using "$temp/fig3adata", table(dist200, order(regvars)) append tstat pval ci

qui xtreg demosenshare_total treatment300 i.year i.stateid, fe cl(group)
regsave treatment300 using "$temp/fig3adata", table(dist300, order(regvars)) append tstat pval ci

qui xtreg demosenshare_total treatment400 i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/fig3adata", table(dist400, order(regvars)) append tstat pval ci

xtreg demosenshare_total treatment500 i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/fig3adata", table(dist500, order(regvars)) append tstat pval ci


use "$temp/fig3adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment50_tstat" 
drop if var == "treatment50_pval" 
drop if var == "treatment100_stderr" 
drop if var == "treatment100_tstat" 
drop if var == "treatment100_pval" 
drop if var == "treatment200_stderr" 
drop if var == "treatment200_tstat" 
drop if var == "treatment200_pval" 
drop if var == "treatment300_stderr" 
drop if var == "treatment300_tstat" 
drop if var == "treatment300_pval" 
drop if var == "treatment400_stderr" 
drop if var == "treatment400_tstat" 
drop if var == "treatment400_pval" 
drop if var == "treatment500_stderr" 
drop if var == "treatment500_tstat" 
drop if var == "treatment500_pval" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 


reshape wide dist, i(var) j(led)

save "$temp/fig3adata", replace
restore

preserve 
use "$input/prec-major-hur", clear
xtset group

qui xtreg demosenshare_total treatment50 i.year i.stateid, fe cl(group)
regsave treatment50 using "$temp/fig3bdata", table(dist50, order(regvars)) replace tstat pval ci

qui xtreg demosenshare_total treatment100 i.year i.stateid, fe cl(group)
regsave treatment100 using "$temp/fig3bdata", table(dist100, order(regvars)) append tstat pval ci

qui xtreg demosenshare_total treatment200 i.year i.stateid, fe cl(group)
regsave treatment200 using "$temp/fig3bdata", table(dist200, order(regvars)) append tstat pval ci

qui xtreg demosenshare_total treatment300 i.year i.stateid, fe cl(group)
regsave treatment300 using "$temp/fig3bdata", table(dist300, order(regvars)) append tstat pval ci

qui xtreg demosenshare_total treatment400 i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/fig3bdata", table(dist400, order(regvars)) append tstat pval ci

xtreg demosenshare_total treatment500 i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/fig3bdata", table(dist500, order(regvars)) append tstat pval ci


use "$temp/fig3bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment50_tstat" 
drop if var == "treatment50_pval" 
drop if var == "treatment100_stderr" 
drop if var == "treatment100_tstat" 
drop if var == "treatment100_pval" 
drop if var == "treatment200_stderr" 
drop if var == "treatment200_tstat" 
drop if var == "treatment200_pval" 
drop if var == "treatment300_stderr" 
drop if var == "treatment300_tstat" 
drop if var == "treatment300_pval" 
drop if var == "treatment400_stderr" 
drop if var == "treatment400_tstat" 
drop if var == "treatment400_pval" 
drop if var == "treatment500_stderr" 
drop if var == "treatment500_tstat" 
drop if var == "treatment500_pval" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 


reshape wide dist, i(var) j(led)

save "$temp/fig3bdata", replace
restore

 
preserve
use "$input/prec-hur", clear
xtset group

xtreg demohouseshare_total treatment50 i.year i.stateid, fe cl(group)
regsave treatment50 using "$temp/fig4adata", table(dist50, order(regvars)) replace tstat pval ci

xtreg demohouseshare_total treatment100 i.year i.stateid, fe cl(group)
regsave treatment100 using "$temp/fig4adata", table(dist100, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment200 i.year i.stateid, fe cl(group)
regsave treatment200 using "$temp/fig4adata", table(dist200, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment300 i.year i.stateid, fe cl(group)
regsave treatment300 using "$temp/fig4adata", table(dist300, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment400 i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/fig4adata", table(dist400, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment500 i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/fig4adata", table(dist500, order(regvars)) append tstat pval ci


use "$temp/fig4adata", clear


drop if var == "treatment50_stderr" 
drop if var == "treatment50_tstat" 
drop if var == "treatment50_pval" 
drop if var == "treatment100_stderr" 
drop if var == "treatment100_tstat" 
drop if var == "treatment100_pval" 
drop if var == "treatment200_stderr" 
drop if var == "treatment200_tstat" 
drop if var == "treatment200_pval" 
drop if var == "treatment300_stderr" 
drop if var == "treatment300_tstat" 
drop if var == "treatment300_pval" 
drop if var == "treatment400_stderr" 
drop if var == "treatment400_tstat" 
drop if var == "treatment400_pval" 
drop if var == "treatment500_stderr" 
drop if var == "treatment500_tstat" 
drop if var == "treatment500_pval" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 


reshape wide dist, i(var) j(led)
save "$temp/fig4adata", replace


use "$input/prec-major-hur", clear
xtset group

xtreg demohouseshare_total treatment50 i.year i.stateid, fe cl(group)
regsave treatment50 using "$temp/fig4bdata", table(dist50, order(regvars)) replace tstat pval ci

xtreg demohouseshare_total treatment100 i.year i.stateid, fe cl(group)
regsave treatment100 using "$temp/fig4bdata", table(dist100, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment200 i.year i.stateid, fe cl(group)
regsave treatment200 using "$temp/fig4bdata", table(dist200, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment300 i.year i.stateid, fe cl(group)
regsave treatment300 using "$temp/fig4bdata", table(dist300, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment400 i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/fig4bdata", table(dist400, order(regvars)) append tstat pval ci

xtreg demohouseshare_total treatment500 i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/fig4bdata", table(dist500, order(regvars)) append tstat pval ci


use "$temp/fig4bdata", clear


drop if var == "treatment50_stderr" 
drop if var == "treatment50_tstat" 
drop if var == "treatment50_pval" 
drop if var == "treatment100_stderr" 
drop if var == "treatment100_tstat" 
drop if var == "treatment100_pval" 
drop if var == "treatment200_stderr" 
drop if var == "treatment200_tstat" 
drop if var == "treatment200_pval" 
drop if var == "treatment300_stderr" 
drop if var == "treatment300_tstat" 
drop if var == "treatment300_pval" 
drop if var == "treatment400_stderr" 
drop if var == "treatment400_tstat" 
drop if var == "treatment400_pval" 
drop if var == "treatment500_stderr" 
drop if var == "treatment500_tstat" 
drop if var == "treatment500_pval" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 


reshape wide dist, i(var) j(led)
save "$temp/fig4bdata", replace
restore

* Figure 5

preserve
use "$input/prec-hur-pt", replace
tabstat demohouseshare_total if evertr==0, by(post)
tabstat demohouseshare_total if evertr==1, by(post)
bysort evertr post: egen house  = mean(demohouseshare_total) 
keep house evertr post
duplicates drop 
save "$temp/fig5bdata", replace

use "$input/prec-hur-pt", replace
tabstat demosenshare_total if evertr==0, by(post)
tabstat demosenshare_total if evertr==1, by(post)
bysort evertr post: egen senate  = mean(demosenshare_total) 
keep senate evertr post
duplicates drop 
save "$temp/fig5adata", replace
restore

* Figure B5

preserve
use "$input/prec-extended-hur", clear

xtset group


qui xtreg demosenshare_total treatment500  i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figb5adata", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400   i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figb5adata", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300     i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb5adata", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200  i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb5adata", table(dist200, order(regvars)) append  ci
qui xtreg demosenshare_total treatment100  i.year  i.stateid, fe cl(group)
regsave treatment100 using "$temp/figb5adata", table(dist100, order(regvars)) append  ci
qui xtreg demosenshare_total treatment50    i.year  i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb5adata", table(dist50, order(regvars)) append  ci

use "$input/prec-extended-major-hur", clear

xtset group

qui xtreg demosenshare_total treatment500  i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figb5bdata", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400   i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figb5bdata", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300     i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb5bdata", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200  i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb5bdata", table(dist200, order(regvars)) append  ci
qui xtreg demosenshare_total treatment100  i.year  i.stateid, fe cl(group)
regsave treatment100 using "$temp/figb5bdata", table(dist100, order(regvars)) append  ci
qui xtreg demosenshare_total treatment50    i.year  i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb5bdata", table(dist50, order(regvars)) append  ci



use "$temp/figb5adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb5adata", replace


use "$temp/figb5bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb5bdata", replace
restore

* Figure B6

preserve
use "$input/prec-extended-hur", clear

xtset group

qui xtreg demohouseshare_total  treatment500  i.year i.stateid , fe cl(group)
regsave treatment500 using "$temp/figb6adata", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400   i.year i.stateid , fe cl(group)
regsave treatment400 using "$temp/figb6adata", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300   i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb6adata", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200   i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb6adata", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100   i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figb6adata", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50   i.year i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb6adata", table(dist50, order(regvars)) append   ci

use "$input/prec-extended-major-hur", clear

xtset group 

qui xtreg demohouseshare_total  treatment500  i.year i.stateid , fe cl(group)
regsave treatment500 using "$temp/figb6bdata", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400   i.year i.stateid , fe cl(group)
regsave treatment400 using "$temp/figb6bdata", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300   i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb6bdata", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200   i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb6bdata", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100   i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figb6bdata", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50   i.year i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb6bdata", table(dist50, order(regvars)) append   ci



use "$temp/figb6adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb6adata", replace

use "$temp/figb6bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb6bdata", replace
restore

* Figure B7


use "$input/prec-extended-hur", clear

xtset group

forvalues i = 1(1)7{
preserve

drop if stateid == `i'

rename treatment500 treatment500_jack`i'
rename treatment400 treatment400_jack`i'
rename treatment300 treatment300_jack`i'
rename treatment200 treatment200_jack`i'
rename treatment100 treatment100_jack`i'
rename treatment50 treatment50_jack`i'

qui xtreg demosenshare_total treatment500_jack`i'  i.year i.stateid, fe cl(group)
regsave treatment500_jack`i' using "$temp/sen_allstate_jack`i'", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400_jack`i'   i.year i.stateid, fe cl(group)
regsave treatment400_jack`i' using "$temp/sen_allstate_jack`i'", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300_jack`i'     i.year i.stateid , fe cl(group)
regsave treatment300_jack`i' using "$temp/sen_allstate_jack`i'", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200_jack`i'  i.year i.stateid , fe cl(group)
regsave treatment200_jack`i' using "$temp/sen_allstate_jack`i'", table(dist200, order(regvars)) append  ci
qui xtreg demosenshare_total treatment100_jack`i'  i.year  i.stateid, fe cl(group)
regsave treatment100_jack`i' using "$temp/sen_allstate_jack`i'", table(dist100, order(regvars)) append  ci
qui xtreg demosenshare_total treatment50_jack`i'    i.year  i.stateid , fe cl(group)
regsave treatment50_jack`i' using "$temp/sen_allstate_jack`i'", table(dist50, order(regvars)) append  ci

qui xtreg demohouseshare_total  treatment500_jack`i'  i.year i.stateid , fe cl(group)
regsave treatment500_jack`i' using "$temp/house_allstate_jack`i'", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400_jack`i'   i.year i.stateid , fe cl(group)
regsave treatment400_jack`i' using "$temp/house_allstate_jack`i'", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300_jack`i'   i.year i.stateid , fe cl(group)
regsave treatment300_jack`i' using "$temp/house_allstate_jack`i'", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200_jack`i'   i.year i.stateid , fe cl(group)
regsave treatment200_jack`i' using "$temp/house_allstate_jack`i'", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100_jack`i'   i.year i.stateid , fe cl(group)
regsave treatment100_jack`i' using "$temp/house_allstate_jack`i'", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50_jack`i'   i.year i.stateid , fe cl(group)
regsave treatment50_jack`i' using "$temp/house_allstate_jack`i'", table(dist50, order(regvars)) append   ci

restore
}

// adding all jacknifes together and cleaning

use "$temp/sen_allstate_jack1", clear
append using "$temp/sen_allstate_jack2"
append using "$temp/sen_allstate_jack3"
append using "$temp/sen_allstate_jack4"
append using "$temp/sen_allstate_jack5"
append using "$temp/sen_allstate_jack6"
append using "$temp/sen_allstate_jack7"

forvalues i= 1(1)7{
drop if var == "treatment50_jack`i'_stderr" 
}

forvalues i= 1(1)7{
drop if var == "treatment100_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment200_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment300_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment400_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment500_jack`i'_stderr" 
}
drop if var == "r2" 
drop if var == "N" 


reshape long dist, i(var) j(led)
drop if dist == .

forvalues i= 1(1)7{
replace var =  "coef_jack`i'" if var == "treatment50_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment100_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment200_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment300_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment400_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment500_jack`i'_coef" 

}

forvalues i= 1(1)7{
replace var =  "ci_upper_jack`i'" if var == "treatment50_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment100_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment200_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment300_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment400_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment500_jack`i'_ci_upper" 
}

forvalues i= 1(1)7{

replace var =  "ci_lower_jack`i'" if var == "treatment50_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment100_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment200_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment300_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment400_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment500_jack`i'_ci_lower" 
}


reshape wide dist, i(var) j(led)


save "$temp/figb7adata", replace

rm "$temp/sen_allstate_jack1.dta"
rm "$temp/sen_allstate_jack2.dta"
rm "$temp/sen_allstate_jack3.dta"
rm "$temp/sen_allstate_jack4.dta"
rm "$temp/sen_allstate_jack5.dta"
rm "$temp/sen_allstate_jack6.dta"
rm "$temp/sen_allstate_jack7.dta"




use "$temp/house_allstate_jack1", clear
append using "$temp/house_allstate_jack2"
append using "$temp/house_allstate_jack3"
append using "$temp/house_allstate_jack4"
append using "$temp/house_allstate_jack5"
append using "$temp/house_allstate_jack6"
append using "$temp/house_allstate_jack7"

forvalues i= 1(1)7{
drop if var == "treatment50_jack`i'_stderr" 
}

forvalues i= 1(1)7{
drop if var == "treatment100_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment200_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment300_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment400_jack`i'_stderr" 
}
forvalues i= 1(1)7{
drop if var == "treatment500_jack`i'_stderr" 
}
drop if var == "r2" 
drop if var == "N" 


reshape long dist, i(var) j(led)
drop if dist == .

forvalues i= 1(1)7{
replace var =  "coef_jack`i'" if var == "treatment50_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment100_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment200_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment300_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment400_jack`i'_coef" 
replace var =  "coef_jack`i'" if var == "treatment500_jack`i'_coef" 

}

forvalues i= 1(1)7{
replace var =  "ci_upper_jack`i'" if var == "treatment50_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment100_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment200_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment300_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment400_jack`i'_ci_upper" 
replace var =  "ci_upper_jack`i'" if var == "treatment500_jack`i'_ci_upper" 
}

forvalues i= 1(1)7{

replace var =  "ci_lower_jack`i'" if var == "treatment50_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment100_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment200_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment300_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment400_jack`i'_ci_lower" 
replace var =  "ci_lower_jack`i'" if var == "treatment500_jack`i'_ci_lower" 
}


reshape wide dist, i(var) j(led)


save "$temp/figb7bdata", replace


rm "$temp/house_allstate_jack1.dta"
rm "$temp/house_allstate_jack2.dta"
rm "$temp/house_allstate_jack3.dta"
rm "$temp/house_allstate_jack4.dta"
rm "$temp/house_allstate_jack5.dta"
rm "$temp/house_allstate_jack6.dta"
rm "$temp/house_allstate_jack7.dta"



* Figure B8

preserve
use "$input/prec-extended-placebo", clear

qui reg demohouseshare_total logd i.countyid if year ==2002, cl(countyid)
regsave logd using "$temp/figb8bdata", table(logd02, order(regvars)) replace ci

qui reg demohouseshare_total logd i.countyid if year ==2004, cl(countyid)
regsave logd using "$temp/figb8bdata", table(logd04, order(regvars)) append ci


qui reg demohouseshare_total logd i.countyid if year ==2006, cl(countyid)
regsave logd using "$temp/figb8bdata", table(logd06, order(regvars)) append ci


qui reg demohouseshare_total logd i.countyid if year ==2008, cl(countyid)
regsave logd using "$temp/figb8bdata", table(logd08, order(regvars)) append ci

qui reg demohouseshare_total logd i.countyid if year ==2010, cl(countyid)
regsave logd using "$temp/figb8bdata", table(log010, order(regvars)) append ci

qui reg demohouseshare_total logd i.countyid if year ==2012, cl(countyid)
regsave logd using "$temp/figb8bdata", table(log012, order(regvars)) append ci

qui reg demohouseshare_total logd i.countyid if year ==2014, cl(countyid)
regsave logd using "$temp/figb8bdata", table(logd014, order(regvars)) append ci

qui reg demohouseshare_total logd i.countyid i.year , cl(countyid) // pooled
regsave logd using "$temp/figb8bdata", table(logdpooled, order(regvars)) append ci


qui reg demosenshare_total logd i.countyid if year ==2002, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd02, order(regvars)) replace ci

qui reg demosenshare_total logd i.countyid if year ==2004, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd04, order(regvars)) append ci

qui reg demosenshare_total logd i.countyid if year ==2006, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd06, order(regvars)) append ci

qui reg demosenshare_total logd i.countyid if year ==2008, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd08, order(regvars)) append ci

qui reg demosenshare_total logd i.countyid if year ==2010, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd10, order(regvars)) append ci

qui reg demosenshare_total logd i.countyid if year ==2012, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd12, order(regvars)) append ci

qui reg demosenshare_total logd i.countyid if year ==2014, cl(countyid)
regsave logd using "$temp/figb8adata", table(logd14, order(regvars)) append ci

qui reg demosenshare_total logd i.countyid i.year , cl(countyid)
regsave logd using "$temp/figb8adata", table(logdpooled, order(regvars)) append ci

use "$temp/figb8bdata", clear

drop if var == "logd_stderr" 
drop if var == "r2" 
drop if var == "N" 


save "$temp/figb8bdata", replace



use "$temp/figb8adata", clear

drop if var == "logd_stderr" 
drop if var == "r2" 
drop if var == "N" 

save "$temp/figb8adata", replace
restore


* Figure B1 

preserve
use "$input/prec-extended-hur-turnout", clear

qui xtreg demosenshare_total treatment500  turnout_reg i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figb1adata", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400  turnout_reg  i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figb1adata", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300  turnout_reg    i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb1adata", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200  turnout_reg i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb1adata", table(dist200, order(regvars)) append  ci
qui xtreg demosenshare_total treatment100  turnout_reg i.year  i.stateid, fe cl(group)
regsave treatment100 using "$temp/figb1adata", table(dist100, order(regvars)) append  ci
qui xtreg demosenshare_total treatment50   turnout_reg  i.year  i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb1adata", table(dist50, order(regvars)) append  ci

use "$input/prec-extended-major-hur-turnout", clear

qui xtreg demosenshare_total treatment500  turnout_reg i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figb1bdata", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400  turnout_reg  i.year i.stateid, fe cl(group)
regsave treatment400 using  "$temp/figb1bdata", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300  turnout_reg    i.year i.stateid , fe cl(group)
regsave treatment300 using  "$temp/figb1bdata", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200  turnout_reg i.year i.stateid , fe cl(group)
regsave treatment200 using  "$temp/figb1bdata", table(dist200, order(regvars)) append  ci
qui xtreg demosenshare_total treatment100  turnout_reg i.year  i.stateid, fe cl(group)
regsave treatment100 using  "$temp/figb1bdata", table(dist100, order(regvars)) append  ci
qui xtreg demosenshare_total treatment50   turnout_reg  i.year  i.stateid , fe cl(group)
regsave treatment50 using  "$temp/figb1bdata", table(dist50, order(regvars)) append  ci


use "$temp/figb1adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb1adata", replace

use "$temp/figb1bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb1bdata", replace
restore

* Figure B2

preserve
use "$input/prec-extended-hur-turnout", clear

qui xtreg demosenshare_total treatment500  turnout_reg democrat_perc i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figb2adata", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400  turnout_reg democrat_perc  i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figb2adata", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300  turnout_reg democrat_perc    i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb2adata", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200  turnout_reg democrat_perc i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb2adata", table(dist200, order(regvars)) append   ci
qui xtreg demosenshare_total treatment100  turnout_reg democrat_perc i.year  i.stateid, fe cl(group)
regsave treatment100 using "$temp/figb2adata", table(dist100, order(regvars)) append   ci
qui xtreg demosenshare_total treatment50   turnout_reg  democrat_perc i.year  i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb2adata", table(dist50, order(regvars)) append   ci

use "$input/prec-extended-major-hur-turnout", clear

qui xtreg demosenshare_total treatment500  turnout_reg democrat_perc i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figb2bdata", table(dist500, order(regvars)) replace   ci
qui xtreg demosenshare_total treatment400  turnout_reg democrat_perc  i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figb2bdata", table(dist400, order(regvars)) append   ci
qui xtreg demosenshare_total treatment300  turnout_reg democrat_perc    i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb2bdata", table(dist300, order(regvars)) append   ci
qui xtreg demosenshare_total treatment200  turnout_reg democrat_perc i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb2bdata", table(dist200, order(regvars)) append   ci
qui xtreg demosenshare_total treatment100  turnout_reg democrat_perc i.year  i.stateid, fe cl(group)
regsave treatment100 using "$temp/figb2bdata", table(dist100, order(regvars)) append   ci
qui xtreg demosenshare_total treatment50   turnout_reg  democrat_perc i.year  i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb2bdata", table(dist50, order(regvars)) append   ci

use "$temp/figb2adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb2adata", replace

use "$temp/figb2bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb2bdata", replace
restore

* Figure B3

preserve
use "$input/prec-extended-hur-turnout", clear


qui xtreg demohouseshare_total  treatment500 turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment500 using "$temp/figb3adata", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment400 using "$temp/figb3adata", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb3adata", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb3adata", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figb3adata", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb3adata", table(dist50, order(regvars)) append   ci

use "$input/prec-extended-major-hur-turnout", clear

qui xtreg demohouseshare_total  treatment500 turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment500 using "$temp/figb3bdata", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment400 using "$temp/figb3bdata", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb3bdata", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb3bdata", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figb3bdata", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50  turnout_reg  i.year i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb3bdata", table(dist50, order(regvars)) append   ci

use "$temp/figb3adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb3adata", replace

use "$temp/figb3bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb3bdata", replace
restore

* Figure B4

preserve

use "$input/prec-extended-hur-turnout", clear

qui xtreg demohouseshare_total  treatment500 turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment500 using "$temp/figb4adata", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment400 using "$temp/figb4adata", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb4adata", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb4adata", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figb4adata", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb4adata", table(dist50, order(regvars)) append   ci



use "$input/prec-extended-major-hur-turnout", clear



qui xtreg demohouseshare_total  treatment500 turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment500 using "$temp/figb4bdata", table(dist500, order(regvars)) replace   ci
qui xtreg demohouseshare_total  treatment400  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment400 using "$temp/figb4bdata", table(dist400, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment300  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figb4bdata", table(dist300, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment200  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figb4bdata", table(dist200, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment100  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figb4bdata", table(dist100, order(regvars)) append   ci
qui xtreg demohouseshare_total  treatment50  turnout_reg  democrat_perc i.year i.stateid , fe cl(group)
regsave treatment50 using "$temp/figb4bdata", table(dist50, order(regvars)) append   ci

use "$temp/figb4adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb4adata", replace


use "$temp/figb4bdata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figb4bdata", replace
restore


* Figure G2

preserve
use "$input/prec-inc-hur", clear

qui xtreg Dincumbentwin_H treatment500 i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figg2adata", table(dist500, order(regvars)) replace ci

qui xtreg Dincumbentwin_H treatment400 i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figg2adata", table(dist400, order(regvars)) append ci

qui xtreg Dincumbentwin_H treatment300 i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figg2adata", table(dist300, order(regvars)) append ci

qui xtreg Dincumbentwin_H treatment200 i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figg2adata", table(dist200, order(regvars)) append ci

qui xtreg Dincumbentwin_H treatment100 i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figg2adata", table(dist100, order(regvars)) append ci

qui xtreg Dincumbentwin_H treatment50 i.year i.stateid, fe cl(group)
regsave treatment50 using "$temp/figg2adata", table(dist50, order(regvars)) append ci

qui xtreg Rincumbentwin_H treatment500 i.year i.stateid, fe cl(group)
regsave treatment500 using "$temp/figg2bdata", table(dist500, order(regvars)) replace ci

qui xtreg Rincumbentwin_H treatment400 i.year i.stateid, fe cl(group)
regsave treatment400 using "$temp/figg2bdata", table(dist400, order(regvars)) append ci

qui xtreg Rincumbentwin_H treatment300 i.year i.stateid , fe cl(group)
regsave treatment300 using "$temp/figg2bdata", table(dist300, order(regvars)) append ci

qui xtreg Rincumbentwin_H treatment200 i.year i.stateid , fe cl(group)
regsave treatment200 using "$temp/figg2bdata", table(dist200, order(regvars)) append ci

qui xtreg Rincumbentwin_H treatment100 i.year i.stateid , fe cl(group)
regsave treatment100 using "$temp/figg2bdata", table(dist100, order(regvars)) append ci

qui xtreg Rincumbentwin_H treatment50 i.year i.stateid, fe cl(group)
regsave treatment50 using "$temp/figg2bdata", table(dist50, order(regvars)) append ci


use "$temp/figg2adata", clear

drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figg2adata", replace

use "$temp/figg2bdata", clear


drop if var == "treatment50_stderr" 
drop if var == "treatment100_stderr" 
drop if var == "treatment200_stderr" 
drop if var == "treatment300_stderr" 
drop if var == "treatment400_stderr" 
drop if var == "treatment500_stderr" 
drop if var == "r2" 
drop if var == "N" 

reshape long dist, i(var) j(led)
drop if dist == .


replace var =  "coef" if var == "treatment50_coef" 
replace var =  "coef" if var == "treatment100_coef" 
replace var =  "coef" if var == "treatment200_coef" 
replace var =  "coef" if var == "treatment300_coef" 
replace var =  "coef" if var == "treatment400_coef" 
replace var =  "coef" if var == "treatment500_coef" 


replace var =  "ci_upper" if var == "treatment50_ci_upper" 
replace var =  "ci_upper" if var == "treatment100_ci_upper" 
replace var =  "ci_upper" if var == "treatment200_ci_upper" 
replace var =  "ci_upper" if var == "treatment300_ci_upper" 
replace var =  "ci_upper" if var == "treatment400_ci_upper" 
replace var =  "ci_upper" if var == "treatment500_ci_upper" 



replace var =  "ci_lower" if var == "treatment50_ci_lower" 
replace var =  "ci_lower" if var == "treatment100_ci_lower" 
replace var =  "ci_lower" if var == "treatment200_ci_lower" 
replace var =  "ci_lower" if var == "treatment300_ci_lower" 
replace var =  "ci_lower" if var == "treatment400_ci_lower" 
replace var =  "ci_lower" if var == "treatment500_ci_lower" 

reshape wide dist, i(var) j(led)

save "$temp/figg2bdata", replace
restore

* Figure G1

preserve
use "$input/prec-nj-hur" , clear

xtset group

qui xtreg demosenshare_total treatment500     i.year , fe cl(group)
estimate store sen500
qui xtreg demosenshare_total treatment400     i.year , fe cl(group)
estimate store sen400
qui xtreg demosenshare_total treatment300      i.year , fe cl(group)
estimate store sen300
qui xtreg demosenshare_total treatment200    i.year , fe cl(group)
estimate store sen200
qui xtreg demosenshare_total treatment100    i.year , fe cl(group)
estimate store sen100
qui xtreg demosenshare_total treatment50      i.year , fe cl(group)
estimate store sen50


esttab sen500 sen400 sen300 sen200 sen100 sen50 using "$temp/figg1adata.csv", b(3) se(3) wide replace

qui xtreg demohouseshare_total  treatment500    i.year , fe cl(group)
estimate store house500
qui xtreg demohouseshare_total  treatment400     i.year , fe cl(group)
estimate store house400
qui xtreg demohouseshare_total  treatment300     i.year , fe cl(group)
estimate store house300
qui xtreg demohouseshare_total  treatment200     i.year , fe cl(group)
estimate store house200
qui xtreg demohouseshare_total  treatment100     i.year , fe cl(group)
estimate store house100
qui xtreg demohouseshare_total  treatment50     i.year , fe cl(group)
estimate store house50

esttab house500 house400 house300 house200 house100 house50 using "$temp/figg1bdata.csv", b(3) se(3) wide replace

import delim "$temp/figg1adata.csv", clear
rename v2 coef500 
rename v3 se500
rename v4 coef400
rename v5 se400
rename v6 coef300
rename v7 se300
rename v8 coef200
rename v9 se200
rename v10 coef100
rename v11 se100
rename v12 coef50
rename v13 se50


replace v1 = subinstr(v1,"=","",.)
replace v1 = subinstr(v1,`"""',"",.)

drop in 1
drop in 1

replace coef500 = subinstr(coef500,"=","",.)
replace coef500 = subinstr(coef500,"*","",.)
replace coef500 = subinstr(coef500,`"""',"",.)

replace se500 = subinstr(se500,"=","",.)
replace se500 = subinstr(se500,`"""',"",.)
replace se500 = subinstr(se500,"(","",.)
replace se500 = subinstr(se500,")","",.)


replace coef400 = subinstr(coef400,"=","",.)
replace coef400 = subinstr(coef400,"*","",.)
replace coef400 = subinstr(coef400,`"""',"",.)

replace se400 = subinstr(se400,"=","",.)
replace se400 = subinstr(se400,`"""',"",.)
replace se400 = subinstr(se400,"(","",.)
replace se400 = subinstr(se400,")","",.)

replace coef300 = subinstr( coef300,"=","",.)
replace coef300 = subinstr( coef300,"*","",.)
replace coef300 = subinstr( coef300,`"""',"",.)

replace se300 = subinstr(se300,"=","",.)
replace se300 = subinstr(se300,`"""',"",.)
replace se300 = subinstr(se300,"(","",.)
replace se300 = subinstr(se300,")","",.)

replace coef200 = subinstr(coef200,"=","",.)
replace coef200 = subinstr(coef200,"*","",.)
replace coef200 = subinstr(coef200,`"""',"",.)

replace se200 = subinstr(se200,"=","",.)
replace se200 = subinstr(se200,`"""',"",.)
replace se200 = subinstr(se200,"(","",.)
replace se200 = subinstr(se200,")","",.)

replace coef100 = subinstr(coef100,"=","",.)
replace coef100 = subinstr(coef100,"*","",.)
replace coef100 = subinstr(coef100,`"""',"",.)

replace se100 = subinstr(se100,"=","",.)
replace se100 = subinstr(se100,`"""',"",.)
replace se100 = subinstr(se100,"(","",.)
replace se100 = subinstr(se100,")","",.)

replace coef50 = subinstr(coef50,"=","",.)
replace coef50 = subinstr(coef50,"*","",.)
replace coef50 = subinstr(coef50,`"""',"",.)

replace se50 = subinstr(se50,"=","",.)  
replace se50 = subinstr(se50,`"""',"",.)
replace se50 = subinstr(se50,"(","",.)
replace se50 = subinstr(se50,")","",.)


destring coef500, gen (coef_500)
drop coef500
rename coef_500 coef500
destring se500, gen (se_500)
drop se500
rename se_500 se500

destring coef400, gen ( coef_400)
drop  coef400
rename  coef_400  coef400
destring se400, gen (se_400)
drop se400
rename se_400 se400


destring coef300, gen (coef_300)
drop coef300
rename coef_300 coef300
destring se300, gen (se_300)
drop se300
rename se_300 se300


destring coef200, gen (coef_200)
drop coef200
rename coef_200 coef200
destring se200, gen (se_200)
drop se200
rename  se_200 se200

destring coef100, gen (coef_100)
drop coef100
rename coef_100 coef100
destring se100, gen ( se_100)
drop  se100
rename  se_100  se100

destring coef50, gen (coef_50)
drop coef50
rename coef_50 coef50

destring se50, gen (se_50)
drop se50
rename se_50 se50


reshape long coef se, i(v1) j(led)
drop if coef == . 
drop if v1 == "2002.year"
drop if v1 == "2004.year"
drop if v1 == "2006.year"
drop if v1 == "2008.year"
drop if v1 == "2010.year"
drop if v1 == "2012.year"
drop if v1 == "N" | v1 == "_cons"

save "$temp/figg1adata", replace


import delim "$temp/figg1bdata.csv", clear
rename v2 coef500 
rename v3 se500
rename v4 coef400
rename v5 se400
rename v6 coef300
rename v7 se300
rename v8 coef200
rename v9 se200
rename v10 coef100
rename v11 se100
rename v12 coef50
rename v13 se50


replace v1 = subinstr(v1,"=","",.)
replace v1 = subinstr(v1,`"""',"",.)

drop in 1
drop in 1

replace coef500 = subinstr(coef500,"=","",.)
replace coef500 = subinstr(coef500,"*","",.)
replace coef500 = subinstr(coef500,`"""',"",.)

replace se500 = subinstr(se500,"=","",.)
replace se500 = subinstr(se500,`"""',"",.)
replace se500 = subinstr(se500,"(","",.)
replace se500 = subinstr(se500,")","",.)


replace coef400 = subinstr(coef400,"=","",.)
replace coef400 = subinstr(coef400,"*","",.)
replace coef400 = subinstr(coef400,`"""',"",.)

replace se400 = subinstr(se400,"=","",.)
replace se400 = subinstr(se400,`"""',"",.)
replace se400 = subinstr(se400,"(","",.)
replace se400 = subinstr(se400,")","",.)

replace coef300 = subinstr( coef300,"=","",.)
replace coef300 = subinstr( coef300,"*","",.)
replace coef300 = subinstr( coef300,`"""',"",.)

replace se300 = subinstr(se300,"=","",.)
replace se300 = subinstr(se300,`"""',"",.)
replace se300 = subinstr(se300,"(","",.)
replace se300 = subinstr(se300,")","",.)

replace coef200 = subinstr(coef200,"=","",.)
replace coef200 = subinstr(coef200,"*","",.)
replace coef200 = subinstr(coef200,`"""',"",.)

replace se200 = subinstr(se200,"=","",.)
replace se200 = subinstr(se200,`"""',"",.)
replace se200 = subinstr(se200,"(","",.)
replace se200 = subinstr(se200,")","",.)

replace coef100 = subinstr(coef100,"=","",.)
replace coef100 = subinstr(coef100,"*","",.)
replace coef100 = subinstr(coef100,`"""',"",.)

replace se100 = subinstr(se100,"=","",.)
replace se100 = subinstr(se100,`"""',"",.)
replace se100 = subinstr(se100,"(","",.)
replace se100 = subinstr(se100,")","",.)

replace coef50 = subinstr(coef50,"=","",.)
replace coef50 = subinstr(coef50,"*","",.)
replace coef50 = subinstr(coef50,`"""',"",.)

replace se50 = subinstr(se50,"=","",.)  
replace se50 = subinstr(se50,`"""',"",.)
replace se50 = subinstr(se50,"(","",.)
replace se50 = subinstr(se50,")","",.)


destring coef500, gen (coef_500)
drop coef500
rename coef_500 coef500
destring se500, gen (se_500)
drop se500
rename se_500 se500

destring coef400, gen ( coef_400)
drop  coef400
rename  coef_400  coef400
destring se400, gen (se_400)
drop se400
rename se_400 se400


destring coef300, gen (coef_300)
drop coef300
rename coef_300 coef300
destring se300, gen (se_300)
drop se300
rename se_300 se300


destring coef200, gen (coef_200)
drop coef200
rename coef_200 coef200
destring se200, gen (se_200)
drop se200
rename  se_200 se200

destring coef100, gen (coef_100)
drop coef100
rename coef_100 coef100
destring se100, gen ( se_100)
drop  se100
rename  se_100  se100

destring coef50, gen (coef_50)
drop coef50
rename coef_50 coef50

destring se50, gen (se_50)
drop se50
rename se_50 se50


reshape long coef se, i(v1) j(led)
drop if coef == . 
drop if v1 == "2002.year"
drop if v1 == "2004.year"
drop if v1 == "2008.year"
drop if v1 == "2010.year"
drop if v1 == "2012.year"
drop if v1 == "N" | v1 == "_cons"

save "$temp/figg1bdata", replace
restore

****************************************
* 			Data Analysis
****************************************

do "./code/2-tabe1" // Produces Table E1
do "./code/3-tabe2" // Produces Table E2
do "./code/5-tabc1" // Produces Table C1
do "./code/6-tabc4" // Produces Table C4
do "./code/7-tabe3" // Produces Table E3
do "./code/8-tabb2" // Produces Table B2
do "./code/9-tabb3" // Produces Table B3
do "./code/10-tabb4" // Produces Table B4
do "./code/11-tabb5" // Produces Table B5
do "./code/12-tabb6" // Produces Table B6
do "./code/13-tabb7" // Produces Table B7
do "./code/14-tabb8" // Produces Table B8
do "./code/15-tabb9" // Produces Table B9
do "./code/16-tabb10" // Produces Table B10
do "./code/17-tabb11" // Produces Table B11

*do "./code/4-start_hrs" // Analysis for Table D1, Table D2, Figure 7, Figure D1, Figure D2, Figure D3, Figure D4, uses data that is not publicly available 
*do "./code/"



********************************************************************************
								* End of Do-File. 
********************************************************************************
